
//自定义异常

public class Test1 {
    public String name = "admin";
    public String passwuord = "1234";

    public void login1(String name, String password) {
        if(!this.name.equals(name)) {
            System.out.println("用户名错误");
            return;
        }
        if(!this.passwuord.equals((password))) {
            System.out.println("密码错误");
            return;
        }
    }

    public void login(String name, String password)
            throws UserNameException,PasswordException {
        if(!this.name.equals(name)) {
            System.out.println("用户名错误");
            throw new UserNameException("姐妹，用户名错误");

        }
        if(!this.passwuord.equals((password))) {
            System.out.println("密码错误");
            throw new PasswordException("姐妹，密码错误");
        }
    }
    public static void main(String[] args) {
        Test1 test = new Test1();
        try {
            test.login("admin","123456");
        }catch (UserNameException e) {
            e.printStackTrace();
            System.out.println("用户名异常");
        }catch (PasswordException passwordException) {
            passwordException.printStackTrace();
            System.out.println("密码异常");
        } finally {

        }

    }
}
